package com.dyh.quickdemozwei.beanOrder;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class BeanOrderConfig {

    static {
        System.out.println("BeanOrderConfig");
    }


    @Bean
    A a(B b){
        StackTraceElement[] traceElements =  Thread.currentThread().getStackTrace();
        /*0 是 Thread.currentThread().getStackTrace()
         * 1 是 com.dyh.quickdemozwei.beanOrder.BeanOrderConfig.b
         * */
        StackTraceElement caller = traceElements[2];
        log.info("初始化A 调用者 {}#{}",caller.getClassName(),caller.getMethodName());
//        B b = b();
        return new A();
    }

    @Bean
    A a1(){
        StackTraceElement[] traceElements =  Thread.currentThread().getStackTrace();
        /*0 是 Thread.currentThread().getStackTrace()
         * 1 是 com.dyh.quickdemozwei.beanOrder.BeanOrderConfig.b
         * */
        StackTraceElement caller = traceElements[2];
        log.info("初始化A1 调用者 {}#{}",caller.getClassName(),caller.getMethodName());

        return new A();
    }

    @Bean
    B b(){
        StackTraceElement[] traceElements =  Thread.currentThread().getStackTrace();
        /*0 是 Thread.currentThread().getStackTrace()
        * 1 是 com.dyh.quickdemozwei.beanOrder.BeanOrderConfig.b
        * */
        StackTraceElement caller = traceElements[2];
        log.info("初始化B 调用者 {}#{}",caller.getClassName(),caller.getMethodName());
        return new B();
    }



}
